import { Component, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { Body, _HttpClient } from '@delon/theme';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { STData } from '@delon/abc';
import { Md5 } from 'ts-md5';
import { ACLService } from '@delon/acl';

@Component({
  selector: 'app-device-alarm',
  templateUrl: './device-alarm.component.html',
  styles: []
})
export class DeviceAlarmComponent implements OnInit {

  @ViewChild('st', { static: false }) st: TablePageComponent;
  selectData: any[];
  loading = false;
  config: SPage = {
    columns: [
      {
        index: 'deviceCode',
        title: '设备SN码',
        width:130,
        filter: {
          placeholder: '请输入设备SN码',
          type: 'string'
        }
      },
      {
        index: 'deviceDescribe',
        title: '设备描述',
        width:100,
        filter: {
          placeholder: '请输入设备描述',
          type: 'string'
        }
      },
      {
        index: 'deviceFac',
        title: '设备厂商',
        width:100,
        filter: {
          placeholder: '请输入厂商',
          type: 'string'
        }
      },
      {
        index: 'eventName',
        title: '报警事件',
        width:120,
        filter:{
          index:"deviceLocation",
          placeholder: '请输入安装地址',
          type: 'string'
        }
      },
      {
        index: 'deviceLocation',
        title: '安装地址',
        width:500,
        filter: {
          index:"eventProduceTime",
          placeholder: '开始时间',
          type: 'date',
        },
      },
      {
        index: 'eventProduceTime',
        title: '上报时间',
        width:200,
        filter:{
          index:"eventDisposeTime",
          type:'date',
          placeholder:"结束时间"
        }
      },
      // {
      //   index: '',
      //   title: '操作',
      //   width:200,
      //   fixed:'right',
      //   buttons:[
      //     {
      //       text:'标记处理',
      //       click:(_record)=>{
      //         this.editStatus();
      //       }
      //     },
      //   ]
      // },
    ],
    showCheckBox: false,
    reqUrl:this.api.alarmManage.devicePage.url,
    defaultParam:{order:'eventProduceTime desc'}
  }
  constructor(private http: _HttpClient,  private api: ApiService, private modal: NzModalService, private message: NzMessageService,private aclService: ACLService) { }
  
  ngOnInit() {

  }
   //标记处理
   editStatus(){
    this.modal.confirm({
      nzTitle:"确定处理?",
      nzOnOk:()=>{
        const body={
          eventDisposeTime : this.getTime(),
          eventDisposeStatus : 6
        }
        this.http.post(this.api.user.delete.url,body).subscribe(res => {
          if (res.status === '200') {
            this.message.success('操作成功');
            this.st.reload();
          }
        })
      }
    })
  }

  _console(e: any): void {
    this.selectData = e;
  }

  dataProcess(data: STData[]){
    console.log(data);
    for(let item of data){
      item.deviceFac="兴天下";
    }
    return data;
  }
  getTime(){
    let date=new Date();
    let year=date.getFullYear();
    let month : string | number=date.getMonth() + 1;
    let day : string | number=date.getDate();
    let h : string | number=date.getHours();
    let m : string | number=date.getMinutes();
    let s : string | number=date.getSeconds();
    month = month < 10 ? "0"+month : month;
    day = day < 10 ? "0"+day : day;
    h = h < 10 ? "0" + h :h;
    m = m < 10 ? "0"+m :m;
    s = s < 10 ? "0"+s:s;

    return year +"-" +month+"-"+day+ " "+h+":"+m+":"+s;
  }
}
